from django.db import models
from utils.model import  BaseModel
from user.models import User
# Create your models here.

class Department(BaseModel):
    name = models.CharField(max_length=64,unique=True,verbose_name="部门名称")
    class Meta:
        db_table = 'demo_department'
        verbose_name = "部门"
        verbose_name_plural = verbose_name
    def __str__(self):
        return "%s" % self.name


class Share_Content(BaseModel):
    name = models.CharField(max_length=128, verbose_name="分享标题")
    cover = models.ImageField(upload_to="cover",verbose_name="封面图片",blank=True,null=True)
    release_time = models.DateField(verbose_name="发布日期", auto_now_add=True)
    cumulative_clicks = models.IntegerField(verbose_name="累计点击次数", default=0)
    sharer = models.ForeignKey("Sharer",on_delete=models.DO_NOTHING, null=True, blank=True, verbose_name="分享者")
    department = models.ForeignKey(Department,on_delete=models.SET_NULL,db_constraint=False, null=True,blank=True,verbose_name="部门名称")
    detail_page = models.OneToOneField('Detail_Page', on_delete=models.DO_NOTHING, null=True, blank=True,
                                         verbose_name="分享详情")

    class Meta:
        db_table = "demo_share_content"
        verbose_name = "分享标题"
        verbose_name_plural = "分享标题"

    def __str__(self):
        return "%s" % self.name


class Detail_Page(BaseModel):
    name = models.CharField(max_length=128, verbose_name="标签",null=True)
    synopsis = models.TextField(max_length=2048, verbose_name="简介", null=True, blank=True)
    video_link = models.CharField(max_length=255, blank=True, null=True, verbose_name="视频链接",help_text="若是video，填vid,若是文档，填link")
    document_link = models.CharField(max_length=255, blank=True, null=True, verbose_name="文档链接",
                                  help_text="若是video，填vid,若是文档，填link")
    vcs=models.CharField(max_length=255, blank=True, null=True, verbose_name="视频封面链接",
                                  help_text="若是video，填vid,若是文档，填link")
    faq = models.TextField(max_length=2048, verbose_name="常见问题", null=True, blank=True)
    class Meta:
        db_table = "demo_detail"
        verbose_name = "详情页"
        verbose_name_plural = verbose_name

    def __str__(self):
        return "%s" % self.name


class Sharer(BaseModel):
    name = models.CharField(max_length=32,verbose_name="分享者")
    title = models.CharField(max_length=32, verbose_name="职位")
    user = models.OneToOneField(User, on_delete=models.DO_NOTHING, null=True, blank=True,verbose_name="用户")
    presentation = models.TextField(max_length=2048, verbose_name="简介", null=True, blank=True)
    class Meta:
        db_table = "demo_sharer"
        verbose_name = "分享者"
        verbose_name_plural = verbose_name

    def __str__(self):
        return "%s" % self.name